<?php
require_once('geoipcity.inc');
// define GEOIP_DAT_FILE
define('GEOIP_DAT_FILE', dirname(__FILE__).'/geolitecity.dat');

// geoip_locate
function geoip_locate($user_ip) {
 
    global $path_visitor_maps;
 
    //geoip_open
    $gi = geoip_open(GEOIP_DAT_FILE, GEOIP_STANDARD);
    $record = geoip_record_by_addr($gi, "$user_ip");
    geoip_close($gi);
 
    // GEOIP_REGION_NAME
    global $GEOIP_REGION_NAME;
    $ret = array();    // Create Result Array
 
    $ret['city_name']    = (isset($record->city)) ? $record->city : '';  // city
    $ret['state_name']   = (isset($record->country_code) && isset($record->region)) // region
          ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : '';
    $ret['state_code']   = (isset($record->region)) ? strtoupper($record->region) : ''; // region code
    $ret['country_name'] = (isset($record->country_name)) ? $record->country_name : '--'; // country
    $ret['country_code'] = (isset($record->country_code)) ? strtoupper($record->country_code) : '--'; // country code
    $ret['latitude']     = (isset($record->latitude)) ? $record->latitude : '0';   // latitude
    $ret['longitude']    = (isset($record->longitude)) ? $record->longitude : '0'; // record
	
	// address locate
	
	$ret['address']		 = iconv('iso-8859-1', 'utf-8', $ret['country_name'].' '.$ret['city_name'].', '.$ret['state_name']);
	$ret['locate']		 = $ret['latitude'].','.$ret['longitude'];
 
    return $ret;
}
?>